<%-- 
    Document   : info
    Created on : Feb 29, 2012, 1:36:52 PM
    Author     : chenwei
--%>

<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@page import="org.chenwei.week10.Student"%>
<%@page import="org.chenwei.week10.DBManager"%>
<%@page import="java.util.*" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<%
    DBManager dbmanager = (DBManager) session.getAttribute("dbmanager");
    List<Student> stuList = dbmanager.searchAll();
    
    request.setAttribute("stulist", stuList);
    session.setAttribute("stulist", stuList);
%>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Student Information</title>
        <style type="text/css">
            #main {
                margin-top: 50px;
            }

            .text {
                width: 120px;
                text-align: right;
                font-weight: bold;
            }

            .textfield {
            }

            .input {
                text-align: center;
            }

            body {
                text-align: center;
            }

            a {
                text-decoration: none;
                color: black;
            }

            table {
                margin: auto;
            }
            
            caption {
                font-weight: bold;
                font-size: large;
            }

            tr,td {
                padding-top: 3px;
                padding-left: 6px;
                padding-right: 6px;
                margin: 3px;
            }
        </style>
        
        <script type="text/javascript">
            function selectAll(form)
            {
                boxes = form.box;
                for (i = 0; i < boxes.length; i++) {
                    boxes[i].checked = true;
                }
            }
            
            function unselectAll(form)
            {
                boxes = form.box;
                for (i = 0; i < boxes.length; i++) {
                    boxes[i].checked = false;
                }
            }
        </script>
    </head>
    <body>
        <a href="/students"><h1>Student Information</h1></a>
        <form method="post" action="/students/information" name="information">
            <div id="main">
                <table border="1">
                    <caption>Choose students:</caption>
                    <tr>
                        <th></th>
                        <th>ID</th>
                        <th>Name</th>
                    </tr>
                    <c:forEach items="${stulist}" var="student" varStatus="loop">
                        <tr>
                            <td><input type="checkbox" name="box" value="${loop.count - 1}" /></td>
                            <td><c:out value="${student.getId()}" /></td>
                            <td><c:out value="${student.getName()}" /></td>
                        </tr>
                    </c:forEach>
                    <tr>
                        <td>
                            <div class="input">
                                <button type="button" onclick="selectAll(document.information);">Select All</button>
                            </div>
                        </td>
                        <td>
                            <div class="input">
                                <button type="button" onclick="unselectAll(document.information)">Unselect All</button>
                            </div>
                        </td>
                        <td>
                            <div class="input">
                                <button type="submit">Submit</button>
                            </div>
                        </td>
                    </tr>
                </table>
            </div>
        </form>
    </body>
</html>
